package edu.sctu.treebuilder.day01;

/**
 * Created by apple on 05/02/2018.
 */
public class StateController {

    private CharacterReader reader;
    private State state = State.StateZero;
    private boolean isTerminated = false;

    public StateController(CharacterReader reader) {
        this.reader = reader;
    }

    // 将当前状态转移到新的状态
    public void transition(State newState){

        this.state = newState;
    }

    public void run() {

        while (!isTerminated) {
            state.read(this, reader);
        }
    }

    public void setTerminated(boolean terminated) {
        isTerminated = terminated;
    }
}
